package com.njg.juc.base;

import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo {
    public synchronized void a(){
        this.b();
        System.out.println("a");
    }

    public synchronized void b(){
        System.out.println("b");
    }








    /**
     * ReentrantLock版本演示可重入锁
     */
    private final ReentrantLock lock = new ReentrantLock();

    public void c()
    {
        lock.lock();
        try
        {
            d();
        }finally {
            lock.unlock();
        }
    }

    public void d()
    {
        lock.lock();
        try
        {
            System.out.println("d");
        }finally {
            lock.unlock();
        }
    }




    public static void main(String[] args) {
        new ReentrantLockDemo().a();
    }
}
